home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / Video Guide (RU) (pic).ifs < prev    next >
Text File  |  2005-03-28  |  16KB  |  532 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=Yan Sorkin       (<link>ysorkin@mail.ru</link>)
  8. Title=VideoGuide
  9. Description=Imports russian movies info with small picture from VideoGuide
  10. Site=http://www.videoguide.ru/
  11. Language=RU
  12. Version=26.11.2002
  13. Requires=3.5.0
  14. Comments=
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19. ***************************************************)
  20.  
  21.  
  22. program VideoGuide;
  23. const
  24.   BaseAddress = 'http://www.videoguide.ru/';
  25. //  BaseAddress = 'http://localhost/';
  26. var
  27.   MovieName: string;
  28.  
  29. function GetTextBlockFrom(Text: string; StartAt: string): string;
  30. var
  31.   TextBlock: string;
  32.   StartPos, EndPos: Integer;
  33. begin
  34.   TextBlock := Text;
  35.   StartPos := pos(StartAt, TextBlock);
  36.   if StartPos > 0 then
  37.   begin
  38.     Delete(TextBlock, 1, StartPos - 1);
  39.     result := TextBlock;
  40.   end;
  41. end;
  42.  
  43. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  44. var
  45.   i: Integer;
  46. begin
  47.   result := -1;
  48.   if StartAt < 0 then
  49.     StartAt := 0;
  50.   for i := StartAt to List.Count-1 do
  51.     if Pos(Pattern, List.GetString(i)) <> 0 then
  52.     begin
  53.       result := i;
  54.       Break;
  55.     end;
  56. end;
  57.  
  58. procedure AnalyzePage(Address: string);
  59. var
  60.   Page: TStringList;
  61.   LineNr: Integer;
  62.   Line: string;
  63.   TextBlock: string;
  64. begin
  65.   Page := TStringList.Create;
  66.   Page.Text := GetPage(Address);
  67.   if pos('<TITLE>┬ΦΣσε├ΦΣ(R) - ╧εΦ±Ω ⌠Φδⁿ∞α "', Page.Text) = 0 then
  68.   begin
  69.     SetField(fieldURL, Address);
  70.     if pos('<TITLE>┬ΦΣσε├ΦΣ(R) - ╨σδΦτ φα DVD', Page.Text) > 0 then
  71.     begin
  72.         AnalyzeVideoPage(Page);
  73.     end else
  74.     if pos('<TITLE>┬ΦΣσε├ΦΣ(R) - ╨σδΦτ φα ΓΦΣσε', Page.Text) > 0 then
  75.     begin
  76.         AnalyzeVideoPage(Page);
  77.     end else
  78.     begin
  79.         AnalyzeMoviePage(Page);
  80.     end;
  81.   end else
  82.   if pos('ReDirect("', Page.Text) > 0 then
  83.   begin
  84.     AnalyzeRedirectPage(Page);
  85.   end else
  86.   begin
  87.     PickTreeClear;
  88.     LineNr := FindLine('┬±σπε φαΘΣσφε ⌠Φδⁿ∞εΓ Γ ε±φεΓφεΘ ßατσ', Page, 0);
  89.     if LineNr > -1 then
  90.     begin
  91.       PickTreeAdd('Movies', '');
  92.       AddMoviesTitles(Page, LineNr);
  93.     end;
  94.     TextBlock := GetTextBlockFrom(Page.Text, '┬±σπε φαΘΣσφε ⌠Φδⁿ∞εΓ Γ ßατσ ΓΦΣσε≡σδΦτεΓ');
  95.     if Length(TextBlock) > 0 then
  96.     begin
  97.       PickTreeAdd('Released on video', '');
  98.       AddReleasesTitles(TextBlock);
  99.     end;
  100.     TextBlock := GetTextBlockFrom(Page.Text, '┬±σπε φαΘΣσφε ⌠Φδⁿ∞εΓ Γ ßατσ ≡σδΦτεΓ DVD');
  101.     if Length(TextBlock) > 0 then
  102.     begin
  103.       PickTreeAdd('Released on DVD', '');
  104.       AddReleasesTitles(TextBlock);
  105.     end;
  106.     LineNr := FindLine('╤∞. ≥αΩµσ:</b> ε±≥αΓ°Φσ±  <a href="', Page, LineNr);
  107.     if LineNr > -1 then
  108.     begin
  109.       AddFindMoreLink(Page, LineNr);
  110.     end;
  111.     if PickTreeExec(Address) then
  112.       AnalyzePage(Address);
  113.   end;
  114.   Page.Free;
  115. end;
  116.  
  117. procedure AnalyzeMoviePage(Page: TStringList);
  118. var
  119.   Line, Value, Value2, FullValue: string;
  120.   LineNr, MovieLength: Integer;
  121.   BeginPos, EndPos: Integer;
  122. begin
  123.  
  124.   // Original Title & Year
  125.   LineNr := FindLine('<TITLE>', Page, 0);
  126.   Line := Page.GetString(LineNr);
  127.   if LineNr > -1 then
  128.   begin
  129.     BeginPos := pos('<TITLE>┬ΦΣσε├ΦΣ(R) - ', Line);
  130.     if BeginPos > 0 then
  131.       BeginPos := BeginPos + 21;
  132.     EndPos := pos(' (', Line);
  133.     if EndPos = 0 then
  134.       EndPos := Length(Line);
  135.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  136.     HTMLDecode(Value);
  137.     Value := AnsiLowerCase(Value);
  138.     Value := AnsiUpFirstLetter(Value);
  139.     SetField(fieldOriginalTitle, Value);
  140.     BeginPos := pos(' ', Line) + 6;
  141.     if BeginPos > 0 then
  142.     begin
  143.       EndPos := Length(Line);
  144.       Value := copy(Line, BeginPos, EndPos - BeginPos);
  145.       BeginPos := pos('(', Value) + 1;
  146.       EndPos := pos(')', Value);
  147.       if (BeginPos > 0) and (EndPos > 0) then
  148.       begin
  149.         FullValue := copy(Value, BeginPos, EndPos - BeginPos);
  150.         SetField(fieldYear, FullValue);
  151.       end;
  152.     end;
  153.   end;
  154.  
  155.   // Director
  156.   LineNr := FindLine('╨σµΦ±±σ≡:', Page, 0);
  157.   if LineNr > -1 then
  158.   begin
  159.     Value := '';
  160.     Line := Page.GetString(LineNr);
  161.     BeginPos := pos('</B> ', Line) + 5;
  162.     EndPos := Length(Line);
  163.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  164.     HTMLDecode(Value);
  165.     HTMLRemoveTags(Value);
  166.     SetField(fieldDirector, Value);
  167.   end;
  168.  
  169.   // Actors
  170.   LineNr := FindLine('┬ ≡εδ ⌡:', Page, 0);
  171.   Value := '';
  172.   Line := Page.GetString(LineNr);
  173.   if LineNr > -1 then
  174.   begin
  175.     BeginPos := pos('</B> ', Line) + 5;
  176.     EndPos := Length(Line);
  177.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  178.     HTMLDecode(Value);
  179.     HTMLRemoveTags(Value);
  180.     SetField(fieldActors, Value);
  181.   end
  182.   else
  183.   begin
  184.   LineNr := FindLine(':</b>   ', Page, 0);
  185.   if LineNr > -1 then
  186.   Value := '';
  187.   Line := Page.GetString(LineNr);
  188.   begin
  189.     BeginPos := pos('</b>  ', Line) + 6;
  190.     EndPos := Length(Line);
  191.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  192.     HTMLDecode(Value);
  193.     HTMLRemoveTags(Value);
  194.     SetField(fieldActors, Value);
  195.   end;
  196.   end;
  197.  
  198.   //Country
  199.   LineNr := FindLine('<br><I>', Page, 0);
  200.   if LineNr > -1 then
  201.   begin
  202.     Line := Page.GetString(LineNr);
  203.     BeginPos := pos('<br><I>', Line) + 7;
  204.     EndPos := pos(' ', Line);
  205.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  206.     HTMLDecode(Value);
  207.     SetField(fieldCountry, Value);
  208.   end;
  209.  
  210.   //Category
  211.   LineNr := FindLine('IdGenre=', Page, 0);
  212.   if LineNr > -1 then
  213.   begin
  214.     Line := Page.GetString(LineNr);
  215.     BeginPos := pos('">', Line) + 2;
  216.     EndPos := pos('</a>', Line);
  217.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  218.     HTMLDecode(Value);
  219.     SetField(fieldCategory, Value);
  220.   end
  221.   else
  222.   begin
  223.   LineNr := FindLine('</small><br />', Page, 0);
  224.   if LineNr > -1 then
  225.   begin
  226.     Line := Page.GetString(LineNr);
  227.     BeginPos := pos('</small><br />', Line) + 14;
  228.     EndPos := pos('</td>', Line);
  229.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  230.     HTMLDecode(Value);
  231.     SetField(fieldCategory, Value);
  232.   end;
  233.   end;
  234.  
  235.   //Year and Length - LineNr is from the previous search
  236.   if LineNr > -1 then
  237.   begin
  238.     Line := Page.GetString(LineNr + 2);
  239.     BeginPos := 1;
  240.     EndPos := pos('; ', Line);
  241.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  242.     HTMLRemoveTags(Value);
  243.     SetField(fieldYear, Value);
  244.  
  245.     BeginPos := pos('; ', Line) + 7;
  246.     EndPos := Length(Line);
  247.     Line := copy(Line, BeginPos, EndPos - BeginPos);
  248.     BeginPos := 1;
  249.     EndPos := pos(',', Line);
  250.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  251.     MovieLength := StrToInt(Value, 0) * 60;
  252.     BeginPos := EndPos + 1;
  253.     EndPos := pos(';&', Line);
  254.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  255.     MovieLength := MovieLength + StrToInt(Value, 0);
  256.     if MovieLength > 0 then
  257.       SetField(fieldLength, IntToStr(MovieLength));
  258.   end;
  259.  
  260.   //Description
  261.   Value2 := '<p align="JUSTIFY">';
  262.   LineNr := FindLine( Value2, Page, 0);
  263.   if LineNr = -1 then
  264.   begin
  265.     Value2 := '<p align=justify>';
  266.     LineNr := FindLine(Value2, Page, 0);
  267.   end;
  268.   if LineNr > -1 then
  269.   begin
  270.     Line := Page.GetString(LineNr);
  271.     BeginPos := pos(Value2, Line) + Length(Value2);
  272.     EndPos := Length(Line);
  273.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  274.     HTMLDecode(Value);
  275.     Value := StringReplace(Value, '<br>', #13#10);
  276.     Value := StringReplace(Value, '<BR>', #13#10);
  277.     Value := StringReplace(Value, '<p', #13#10#13#10 + '<p');
  278.     HTMLRemoveTags(Value);
  279.     SetField(fieldDescription, Value);
  280.   end;
  281.  
  282.   // Picture
  283.   LineNr := FindLine('<img src="\img\films\', Page, 0);
  284.   if LineNr = -1 then
  285.     LineNr := FindLine('<img src="/img/films/', Page, 0);
  286.   if LineNr > -1 then
  287.   begin
  288.     Line := Page.GetString(LineNr);
  289.     BeginPos := pos('src="', Line) + 4;
  290.     Delete(Line, 1, BeginPos);
  291.     EndPos := pos('"', Line);
  292.     Value := copy(Line, 1, EndPos - 1);
  293.     GetPicture(Value);
  294.   end;
  295.  
  296. end;
  297.  
  298. procedure AnalyzeVideoPage(Page: TStringList);
  299. var
  300.   Line, Value, Value2, FullValue: string;
  301.   LineNr, MovieLength: Integer;
  302.   BeginPos, EndPos: Integer;
  303. begin
  304.  
  305.   // Title, Original Title, Country, Year, Length, Category
  306.   LineNr := FindLine('<p><b><a href="card_film.asp?IDFilm=', Page, 0);
  307.   if LineNr = -1 then
  308.     LineNr := FindLine('<p><b><font color="Navy">', Page, 0);
  309.   if LineNr > -1 then
  310.   begin
  311.     Line := Page.GetString(LineNr);
  312.     // Title
  313.     BeginPos := pos('">', Line) + 2;
  314.     EndPos := pos('</b>', Line);
  315.     if EndPos = 0 then
  316.       EndPos := Length(Line);
  317.     FullValue := copy(Line, BeginPos, EndPos - BeginPos);
  318.     HTMLDecode(FullValue);
  319.     HTMLRemoveTags(FullValue);
  320.     FullValue := AnsiLowerCase(FullValue);
  321.     FullValue := AnsiUpFirstLetter(FullValue);
  322.     SetField(fieldOriginalTitle, FullValue);
  323.  
  324.     // Original Title (if exists)
  325.     BeginPos := pos('<br><small>/', Line) + 12;
  326.     EndPos := pos('/  ', Line);
  327.     if (BeginPos > 0) and (EndPos > 0) then
  328.     begin
  329.       Value := copy(Line, BeginPos, EndPos - BeginPos);
  330.       HTMLDecode(Value);
  331.       HTMLRemoveTags(Value);
  332.       Value := AnsiLowerCase(Value);
  333.       Value := AnsiMixedCase(Value, ' .-');
  334.       SetField(fieldOriginalTitle, Value);
  335.       SetField(fieldTranslatedTitle, FullValue);
  336.       Delete(Line, 1, EndPos + 7);
  337.     end;
  338.  
  339.     // Country
  340.     BeginPos := pos('<br><small>', Line);
  341.     if BeginPos = 0 then
  342.       BeginPos := 1;
  343.     EndPos := pos('  ', Line);
  344.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  345.     HTMLDecode(Value);
  346.     HTMLRemoveTags(Value);
  347.     SetField(fieldCountry, Value);
  348.     Delete(Line, 1, EndPos + 6);
  349.  
  350.     // Year and Length
  351.     BeginPos := 1;
  352.     EndPos := pos('  ', Line);
  353.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  354.     SetField(fieldYear, Value);
  355.  
  356.     BeginPos := pos('  ', Line) + 7;
  357.     EndPos := pos(' ∞Φφ', Line);
  358.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  359.     SetField(fieldLength, Value);
  360.   end;
  361.  
  362.   //Category
  363.   LineNr := FindLine('</small><br />', Page, 0);
  364.   if LineNr > -1 then
  365.   begin
  366.     Line := Page.GetString(LineNr);
  367.     BeginPos := pos('/>', Line) + 2;
  368.     EndPos := Length(Line) + 1;
  369.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  370.     HTMLDecode(Value);
  371.     SetField(fieldCategory, Value);
  372.   end;
  373.  
  374.   // Director
  375.   LineNr := FindLine('╨σµΦ±±σ≡:', Page, 0);
  376.   if LineNr > -1 then
  377.   begin
  378.     Line := Page.GetString(LineNr);
  379.     BeginPos := pos('</b> ', Line) + 5;
  380.     EndPos := Length(Line) + 1;
  381.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  382.     HTMLDecode(Value);
  383.     HTMLRemoveTags(Value);
  384.     SetField(fieldDirector, Value);
  385.   end;
  386.  
  387.   // Actors
  388.   LineNr := FindLine('┬ ≡εδ ⌡:', Page, 0);
  389.   if LineNr > -1 then
  390.   begin
  391.     Line := Page.GetString(LineNr);
  392.     BeginPos := pos('</b> ', Line) + 6;
  393.     EndPos := Length(Line);
  394.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  395.     HTMLDecode(Value);
  396.     HTMLRemoveTags(Value);
  397.     SetField(fieldActors, Value);
  398.   end;
  399.  
  400.   //Description
  401.   LineNr := FindLine('<p align="justify">', Page, 0);
  402.   if LineNr > -1 then
  403.   begin
  404.     Line := Page.GetString(LineNr);
  405.     BeginPos := pos('<p align="justify">', Line) + 19;
  406.     EndPos := Length(Line);
  407.     Value := copy(Line, BeginPos, EndPos - BeginPos);
  408.     HTMLDecode(Value);
  409.     Value := StringReplace(Value, '<br>', #13#10);
  410.     Value := StringReplace(Value, '<BR>', #13#10);
  411.     Value := StringReplace(Value, '<p', #13#10#13#10 + '<p');
  412.     HTMLRemoveTags(Value);
  413.     SetField(fieldDescription, Value);
  414.   end;
  415.  
  416.   // Picture
  417.   LineNr := FindLine('<img src="\img\films\', Page, 0);
  418.   if LineNr = -1 then
  419.     LineNr := FindLine('<img src="/img/films/', Page, 0);
  420.   if LineNr = -1 then
  421.     LineNr := FindLine('<img src="\img\rel\', Page, 0);
  422.   if LineNr = -1 then
  423.     LineNr := FindLine('<img src="/img/rel/', Page, 0);
  424.   if LineNr = -1 then
  425.     LineNr := FindLine('<img src="\img\dvd\', Page, 0);
  426.   if LineNr = -1 then
  427.     LineNr := FindLine('<img src="/img/dvd/', Page, 0);
  428.   if LineNr > -1 then
  429.   begin
  430.     Line := Page.GetString(LineNr);
  431.     BeginPos := pos('src="', Line) + 4;
  432.     Delete(Line, 1, BeginPos);
  433.     EndPos := pos('"', Line);
  434.     Value := copy(Line, 1, EndPos - 1);
  435.     GetPicture(Value);
  436.   end;
  437.  
  438. end;
  439.  
  440. procedure AnalyzeRedirectPage(Page: TStringList);
  441. var
  442.   Address: string;
  443.   BeginPos, EndPos: Integer;
  444. begin
  445.   BeginPos := pos('ReDirect("', Page.Text) + 10;
  446.   EndPos := pos('")</script>', Page.Text);
  447.   Address := BaseAddress + copy(Page.Text, BeginPos, EndPos - BeginPos);
  448.   AnalyzePage(Address);
  449. end;
  450.  
  451. procedure AddFindMoreLink(Page: TStringList; var LineNr: Integer);
  452. var
  453.   Line, Value, Address: string;
  454.   StartPos, EndPos: Integer;
  455. begin
  456.   Line := Page.GetString(LineNr);
  457.   StartPos := pos('╤∞. ≥αΩµσ:</b> ε±≥αΓ°Φσ±  <a href="', Line) + 35;
  458.   EndPos := pos('</a> ⌠Φδⁿ∞', Line);
  459.   Value := copy(Line, StartPos, EndPos - StartPos);
  460.   StartPos := 1;
  461.   EndPos := pos('">', Value);
  462.   Address := BaseAddress + copy(Value, StartPos, EndPos - StartPos);
  463.   PickTreeMoreLink(Address);
  464. end;
  465.  
  466. procedure AddMoviesTitles(Page: TStringList; var LineNr: Integer);
  467. var
  468.   Line: string;
  469.   MovieTitle, MovieAddress: string;
  470.   StartPos, EndPos: Integer;
  471. begin
  472.   repeat
  473.     LineNr := LineNr + 1;
  474.     Line := Page.GetString(LineNr);
  475.     StartPos := pos('="', Line);
  476.     EndPos := pos('</OL>', Line);
  477.     if (StartPos > 0) and (EndPos = 0) then
  478.     begin
  479.       StartPos := StartPos + 2;
  480.       MovieAddress := copy(Line, StartPos, pos('">', Line) - StartPos);
  481.       StartPos := pos('">', Line) + 2;
  482.       MovieTitle := copy(Line, StartPos, pos('</a>', Line) - StartPos);
  483.       Line := Page.GetString(LineNr + 1);
  484.       MovieTitle := MovieTitle + copy(Line, 1, pos('</small>', Line) - 1);
  485.       HTMLDecode(Movietitle);
  486.       HTMLRemoveTags(MovieTitle);
  487.       PickTreeAdd(MovieTitle, BaseAddress + MovieAddress);
  488.     end;
  489.   until EndPos > 0;
  490. end;
  491.  
  492. procedure AddReleasesTitles(TextBlock: string);
  493. var
  494.   MovieTitle, MovieAddress: string;
  495.   StartPos, EndPos, EndTablePos: Integer;
  496. begin
  497.   repeat
  498.     StartPos := pos('<td><b><a href="', TextBlock);
  499.     EndTablePos :=  pos('</table>', TextBlock);
  500.     if StartPos > 0 then
  501.     begin
  502.       Delete(TextBlock, 1, StartPos - 1);
  503.     end;
  504.     if (StartPos > 0) and (StartPos < EndTablePos) then
  505.     begin
  506.       EndPos := pos('</td>', TextBlock);
  507.       MovieTitle := copy(TextBlock, 1, EndPos - 1);
  508.       HTMLDecode(MovieTitle);
  509.       HTMLRemoveTags(MovieTitle);
  510.       MovieAddress := copy(TextBlock, 17, pos('">', TextBlock) - 17);
  511.       PickTreeAdd(MovieTitle, BaseAddress + MovieAddress);
  512.       Delete(TextBlock, 1, EndPos - 1);
  513.     end;
  514.   until (StartPos = 0) or (StartPos > EndTablePos);
  515. end;
  516.  
  517. begin
  518.   if CheckVersion(3,5,0) then
  519.   begin
  520.     MovieName := GetField(fieldOriginalTitle);
  521.     if MovieName = '' then
  522.       MovieName := GetField(fieldTranslatedTitle);
  523.     if Input('Import from VideoGuide', 'Enter the title of the movie:', MovieName) then
  524.     begin
  525.       AnalyzePage('http://www.videoguide.ru/find.asp?Search=Simple&types=film&titles='+UrlEncode(MovieName));
  526. //      AnalyzePage('http://localhost/search1.htm');
  527.     end;
  528.   end else
  529.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
  530. end.
  531.  
  532.